package com.asiainfo.dacp.datastash.broker.tracelog;

import com.asiainfo.dacp.datastash.broker.core.vo.StashUnit;
import com.asiainfo.dacp.datastash.broker.core.vo.StashUnitProcess;
import com.asiainfo.dacp.datastash.broker.core.vo.StashUnitTask;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 日志的值对象
 * @author MeiKefu
 * @date 2017-11-30
 */
@Data
@NoArgsConstructor
public class StashTraceLogVo implements Serializable {

    private String clzName;
    private String event;
    private String message;
    private String unitCode="";
    private String batchNo="";
    private String unitProcId="";
    private String taskProcId="";
    private String level = "info";

    private String threadName=Thread.currentThread().getName();

    public StashTraceLogVo(String clzName,String event,String message){
        this.event=event;
        this.clzName=clzName;
        this.message=message;
    }

    public StashTraceLogVo(String clzName,String event,String message,String unitCode,String batchNo,String unitProcId){
        this.event=event;
        this.clzName=clzName;
        this.message=message;
        this.unitCode = unitCode;
        this.batchNo = batchNo;
        this.unitProcId=unitProcId;
    }

    public StashTraceLogVo(String clzName,String event,String message,String unitCode,String batchNo,String unitProcId,String taskProcId){
        this.event=event;
        this.clzName=clzName;
        this.message=message;
        this.unitCode = unitCode;
        this.batchNo = batchNo;
        this.unitProcId=unitProcId;
        this.taskProcId=taskProcId;
    }

    public StashTraceLogVo level(String level){
        this.level = level;
        return this;
    }

    public static StashTraceLogVo buildStashTraceLogVo(String clzName,String event, String message,String unitCode,String batchNo,String unitProcId){
        return new StashTraceLogVo(clzName,event,message
                ,unitCode,batchNo,unitProcId);
    }

    public static StashTraceLogVo buildStashTraceLogVo(StashUnit stashUnit, String clzName, String event, String message){
        return new StashTraceLogVo(clzName,event,message
                ,stashUnit.getUnitCode(),stashUnit.getBatchNo(),stashUnit.getUnitProcId());
    }

    public static StashTraceLogVo buildStashTraceLogVo(StashUnitProcess stashUnitProcessing, String clzName, String event,  String message){
        return new StashTraceLogVo(clzName,event,message
                ,stashUnitProcessing.getUnitCode(),stashUnitProcessing.getBatchNo(),stashUnitProcessing.getUnitProcId()
        );
    }

    public static StashTraceLogVo buildStashTraceLogVo(StashUnitTask stashUnitTask, String clzName, String event, String message){
        //TODO 未记录broker id

        return new StashTraceLogVo(clzName, event,message
                ,stashUnitTask.getUnitCode(),stashUnitTask.getBatchNo(),stashUnitTask.getUnitProcId()
                ,stashUnitTask.getTaskProcId()
        );
    }
}
